package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.domain.NewsPage;
import cn.wolfcode.trip.base.domain.StrategyDetail;
import cn.wolfcode.trip.base.query.NewsPageQueryObject;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.INewsPageService;
import cn.wolfcode.trip.base.util.JsonResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("newsPage")
public class NewsPageController {

    @Autowired
    private INewsPageService newsPageService;

    @RequestMapping("list")
    public String list(@ModelAttribute("qo")NewsPageQueryObject qo, Model mo){
        PageInfo<NewsPage> query = newsPageService.query(qo);
        mo.addAttribute("pageInfo",query);
        return "newsPage/list";
    }

    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(NewsPage newsPage) {
        JsonResult result = new JsonResult();
        try {
            newsPageService.saveOrUpdate(newsPage);
        } catch (Exception e) {
            e.printStackTrace();
            result.mark("亲，操作失败，请重试");
        }
        return result;
    }
}
